#include "MsnContact.h"
#include "MsnDef.h"

bool MsnContact::IsOnline()
{
	return !status.IsEmpty() && !status.IsSameAs(_T("OFF"));
}

bool MsnContact::IsOffLine()
{
	return status.IsSameAs(_T("OFF")) || status.IsEmpty();
}

bool MsnContact::IsInList(int listCode)
{
	return (listNumber & listCode) == listCode;
}

void MsnContact::AddList(int listCode)
{
	//TODO check whether listCode is legal
	if(!IsInList(listCode)){
		listNumber += listCode;
	}
}

void MsnContact::RemoveList(int listCode)
{
	//TODO check whether listCode is legal
	if(IsInList(listCode)){
		listNumber -= listCode;
	}
}

wxString MsnContact::GetStatus()
{
	if(IsInList(BLOCKED)){
		return _T("BLK");
	}
	return status;
}

    wxString MsnContact::GetDisplayName(){
        if(!nickname.IsEmpty()) return nickname;
        if(!name.IsEmpty()) return name;

        return passport;
    }

    bool MsnContact::HasNickname(){
        return !nickname.IsEmpty();
    }

    wxString MsnContact::GetFirstGroup()
    {
        if(groupList.IsEmpty())
            return wxEmptyString;
        else
            return groupList.Item(0);
    }

    wxString MsnContact::GetGroupString()
    {
        wxString result;
        for(unsigned int i=0;i<groupList.GetCount();i++){
            result << groupList.Item(i);
            if(i < groupList.GetCount()-1)
                result << _T(",");
        }
        return result;
    }

    void MsnContact::SetGroupString(const wxString& groups)
    {
		groupList.clear();
        wxStringTokenizer st(groups, _T(","));
        while(st.HasMoreTokens()){
            groupList.Add(st.GetNextToken());
        }
    }

    void MsnContact::RemoveGroup(const wxString& groupID)
    {
        if(!groupID.IsEmpty())
            groupList.Remove(groupID);
    }
    void MsnContact::AddGroup(const wxString& groupID)
    {
        if(!groupID.IsEmpty())
            groupList.Add(groupID);
    }

